package icu.lookyousmileface.singlemode;

/**
 * @author starrysky
 * @title: LazyMan
 * @projectName Juc_Pro
 * @description: 懒汉单例模式
 * @date 2021/1/304:52 下午
 */
public class LazyMan {

    private  volatile static LazyMan lazyMan;
    private static boolean lockSkey = false;

    private LazyMan() {
        synchronized (LazyMan.class){
            if (lockSkey == false){
                lockSkey = true;
            }else {
                throw new RuntimeException("不要妄图使用反射破坏！");
            }
        }
    }
    // 双重检测锁模式的 懒汉式单例 DCL懒汉式
    public static LazyMan getInstance() {
        if (lazyMan == null) {
            synchronized (LazyMan.class){
                if (lazyMan==null){
                    lazyMan = new LazyMan();
                }
            }
        }
        return lazyMan;
    }

}
